{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Agent Demo with Simplified Connection Management\n",
    "\n",
    "This notebook demonstrates an agent using multiple tool types with simplified connection management:\n",
    "1. **Local Calculator**: Mathematical expressions via MCP\n",
    "2. **Brave Search**: Web search via MCP (if API key available)\n",
    "3. **Think Tool**: Internal reasoning tool"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import sys\n",
    "import nest_asyncio\n",
    "nest_asyncio.apply()\n",
    "\n",
    "parent_dir = os.path.dirname(os.getcwd())\n",
    "sys.path.insert(0, parent_dir)\n",
    "from agents.agent import Agent, ModelConfig\n",
    "from agents.tools.think import ThinkTool\n",
    "from agents.tools.web_search import WebSearchServerTool\n",
    "from agents.tools.code_execution import CodeExecutionServerTool"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 1. Configure tools and MCP servers"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Calculator server configured: Yes\n",
      "Brave API key available: Yes\n",
      "Brave search server configured: Yes\n"
     ]
    }
   ],
   "source": [
    "# Standard Python tool\n",
    "think_tool = ThinkTool()\n",
    "\n",
    "# Python MCP server\n",
    "calculator_server_path = os.path.abspath(os.path.join(os.getcwd(), \"tools/calculator_mcp.py\"))\n",
    "calculator_server = {\n",
    "    \"type\": \"stdio\",\n",
    "    \"command\": \"python\",\n",
    "    \"args\": [calculator_server_path]\n",
    "}\n",
    "print(f\"Calculator server configured: {'Yes' if calculator_server else 'No'}\")\n",
    "\n",
    "\n",
    "# Brave MCP server written in TypeScript\n",
    "\n",
    "brave_api_key = os.environ.get(\"BRAVE_API_KEY_BASE_DATA\", \"\")\n",
    "print(f\"Brave API key available: {'Yes' if brave_api_key else 'No'}\")\n",
    "brave_search_server = {\n",
    "    \"type\": \"stdio\",\n",
    "    \"command\": \"npx\",\n",
    "    \"args\": [\"-y\", \"@modelcontextprotocol/server-brave-search\"],\n",
    "    \"env\": {\n",
    "        \"BRAVE_API_KEY\": brave_api_key, \n",
    "        \"PATH\": f\"{os.path.dirname('npx')}:\" + os.environ.get(\"PATH\", \"\")\n",
    "    }\n",
    "}\n",
    "print(f\"Brave search server configured: {'Yes' if brave_search_server else 'No'}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 2. Initialize agent with combined tools"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "[Multi-Tool Agent] Agent initialized\n"
     ]
    }
   ],
   "source": [
    "# Create agent config \n",
    "system_prompt = \"\"\"\n",
    "You are a helpful assistant with access to:\n",
    "1. Web search (brave_web_search, brave_local_search)\n",
    "2. Mathematical calculator (calculate) \n",
    "3. A tool to think and reason (think)\n",
    "\n",
    "Always use the most appropriate tool for each task.\n",
    "\"\"\"\n",
    "\n",
    "\n",
    "# Initialize agent with standard tools and MCP servers\n",
    "agent = Agent(\n",
    "    name=\"Multi-Tool Agent\",\n",
    "    system=system_prompt,\n",
    "    tools=[think_tool], \n",
    "    mcp_servers=[brave_search_server, calculator_server], \n",
    "    config=ModelConfig(\n",
    "        model=\"claude-3-7-sonnet-20250219\", \n",
    "        max_tokens=4096,\n",
    "        temperature=1.0\n",
    "    ),\n",
    "    verbose=True\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 3. Run queries"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Loaded 3 MCP tools from 2 servers.\n",
      "\n",
      "[Multi-Tool Agent] Received: What's the square root of the OKC population in 2022\n",
      "\n",
      "[Multi-Tool Agent] Output: I'll help you find the square root of Oklahoma City's population in 2022. First, I need to look up the population data, then I can calculate the square root.\n",
      "\n",
      "[Multi-Tool Agent] Tool call: brave_web_search(query=Oklahoma City population 2022 census data)\n",
      "\n",
      "[Multi-Tool Agent] Tool result: Title: Oklahoma Cities by Population (2025)\n",
      "Description: The most populous cities in Oklahoma are <strong>Oklahoma City with 702,767</strong>, Tulsa at 411,894, Norman with 130,046, Broken Arrow at 119,194, and Edmond with 98,103. You can get the most current Census population data for all 834 Oklahoma cities, sorted from the most populous cities in Oklahoma to the ...\n",
      "URL: https://www.oklahoma-demographics.com/cities_by_population\n",
      "\n",
      "Title: U.S. Census Bureau QuickFacts: Oklahoma City city, Oklahoma\n",
      "Description: QuickFacts provides statistics for all states and counties. Also for cities and towns with a population of <strong>5,000 or more</strong>. ... Methodology differences may exist between data sources, and so estimates from different sources are not comparable.\n",
      "URL: https://www.census.gov/quickfacts/fact/table/oklahomacitycityoklahoma/PST045224\n",
      "\n",
      "Title: Oklahoma City lands in top 20 of largest US cities by population: New census data\n",
      "Description: More: 10 Oklahoma cities where population is growing the fastest · Oklahoma City grew by about 1% between 2022 and 2023, adding <strong>7,589 people</strong>. And between the 2010 and 2020 Censuses, Oklahoma City was one of 14 American cities that added more than 100,000 people.\n",
      "URL: https://www.oklahoman.com/story/news/2024/05/17/oklahoma-city-population-top-20-us-census-data-growth/73729737007/\n",
      "\n",
      "Title: Oklahoma City - Wikipedia\n",
      "Description: Oklahoma City (/ˌoʊkləˈhoʊmə ... it ranks 20th in population among U.S. cities and 8th in the Southern United States, with a population of <strong>681,054 at the 2020 census</strong>....\n",
      "URL: https://en.wikipedia.org/wiki/Oklahoma_City\n",
      "\n",
      "Title: Oklahoma City city, Oklahoma - Census Bureau Profile\n",
      "Description: We&#x27;re sorry but this website doesn&#x27;t work properly without JavaScript enabled. Please enable it to continue\n",
      "URL: https://data.census.gov/profile/Oklahoma_City_city,_Oklahoma?g=160XX00US4055000\n",
      "\n",
      "Title: Oklahoma City, Oklahoma Population 2025\n",
      "Description: Oklahoma City is a city located in Cleveland County, Oklahoma. Oklahoma City has a <strong>2025 population of 715,893</strong>. Oklahoma City is currently growing at a rate of 0.93% annually and its population has increased by 4.8% since the most recent census, which recorded a population of 683,078 in 2020.\n",
      "URL: https://worldpopulationreview.com/us-cities/oklahoma/oklahoma-city\n",
      "\n",
      "Title: Oklahoma Demographics | Current Census Data\n",
      "Description: Get the Oklahoma demographic data that you need. You can get the most current Oklahoma data from the US Census Bureau without spending 40 high-value hours searching the internet. The Oklahoma population is <strong>4,053,824 people</strong> according to the US Census Bureau&#x27;s 2023 Population Estimates Program.\n",
      "URL: https://www.oklahoma-demographics.com/\n",
      "\n",
      "Title: Oklahoma City, OK - Profile data - Census Reporter\n",
      "Description: a little less than the figure in the Oklahoma City, OK Metro Area: <strong>23.5 14,717,310</strong> (±0.2 / ±145,724)\n",
      "URL: https://censusreporter.org/profiles/16000US4055000-oklahoma-city-ok/\n",
      "\n",
      "Title: Oklahoma population by year, county, race, & more | USAFacts\n",
      "Description: The ages, races, and <strong>population</strong> density of <strong>Oklahoma</strong> tell a story. Understand the shifts in demographic trends with these charts visualizing decades of <strong>population</strong> <strong>data</strong>. ... Florida K-12 public teachers are paid the lowest average salary when adjusted for cost of living.Published on November 8, <strong>2022</strong> ... <strong>The</strong> <strong>Census</strong> ...\n",
      "URL: https://usafacts.org/data/topics/people-society/population-and-demographics/our-changing-population/state/oklahoma/\n",
      "\n",
      "Title: Resident Population in Oklahoma City, OK (MSA) (OKCPOP) | FRED | St. Louis Fed\n",
      "Description: Graph and download economic <strong>data</strong> for Resident <strong>Population</strong> <strong>in</strong> <strong>Oklahoma</strong> <strong>City</strong>, OK (MSA) (OKCPOP) from 2000 to 2024 about <strong>Oklahoma</strong> <strong>City</strong>, OK, residents, <strong>population</strong>, and USA.\n",
      "URL: https://fred.stlouisfed.org/series/OKCPOP\n",
      "\n",
      "[Multi-Tool Agent] Output: Based on the search results, I can see multiple population figures for Oklahoma City in different years. The most relevant information for 2022 specifically isn't directly provided, but I can see:\n",
      "\n",
      "- 2020 census: 681,054 people\n",
      "- 2023 estimate showing growth of 7,589 people from 2022\n",
      "- 2025 projection: 715,893 people\n",
      "\n",
      "Let me search more specifically for the 2022 population:\n",
      "\n",
      "[Multi-Tool Agent] Tool call: brave_web_search(query=Oklahoma City population 2022 exact figure)\n",
      "\n",
      "[Multi-Tool Agent] Tool result: Title: Oklahoma City, Oklahoma Population 2025\n",
      "Description: Oklahoma City is a city located in Cleveland County, Oklahoma. Oklahoma City has a <strong>2025 population of 715,893</strong>.\n",
      "URL: https://worldpopulationreview.com/us-cities/oklahoma/oklahoma-city\n",
      "\n",
      "Title: Oklahoma City Metro Area Population 1950-2025\n",
      "Description: The metro area population of Oklahoma City in 2022 was <strong>1,008,000</strong>, a 1% increase from 2021.\n",
      "URL: https://www.macrotrends.net/cities/23088/oklahoma-city/population\n",
      "\n",
      "Title: Oklahoma City city, Oklahoma - Census Bureau Profile\n",
      "Description: We&#x27;re sorry but this website doesn&#x27;t work properly without JavaScript enabled. Please enable it to continue\n",
      "URL: https://data.census.gov/profile/Oklahoma_City_city,_Oklahoma?g=160XX00US4055000\n",
      "\n",
      "Title: Oklahoma City - Wikipedia\n",
      "Description: The Oklahoma City metropolitan area has an estimated <strong>1.49 million</strong> residents, the largest metropolitan area in the state and 42nd-most populous in the nation. The city limits extend into Canadian, Cleveland, and Pottawatomie counties; however, areas beyond Oklahoma County primarily consist of ...\n",
      "URL: https://en.wikipedia.org/wiki/Oklahoma_City\n",
      "\n",
      "Title: U.S. Census Bureau QuickFacts: Oklahoma City city, Oklahoma\n",
      "Description: QuickFacts provides statistics for all states and counties. Also for cities and towns with a population of <strong>5,000 or more</strong>.\n",
      "URL: https://www.census.gov/quickfacts/oklahomacitycityoklahoma\n",
      "\n",
      "Title: Oklahoma City, OK | Data USA\n",
      "Description: As of 2023, 12% of Oklahoma City, OK residents <strong>(82.6k people</strong>) were born outside of the United States, which is lower than the national average of 13.8%. In 2022, the percentage of foreign-born citizens in Oklahoma City, OK was 11.8%, meaning that the rate has been increasing.\n",
      "URL: https://datausa.io/profile/geo/oklahoma-city-ok\n",
      "\n",
      "Title: Oklahoma City lands in top 20 of largest US cities by population: New census data\n",
      "Description: More: 10 Oklahoma cities where population is growing the fastest · Oklahoma City grew by about 1% between 2022 and 2023, adding <strong>7,589 people</strong>.\n",
      "URL: https://www.oklahoman.com/story/news/2024/05/17/oklahoma-city-population-top-20-us-census-data-growth/73729737007/\n",
      "\n",
      "Title: Oklahoma Cities by Population (2025)\n",
      "Description: The most populous cities in Oklahoma are Oklahoma City with <strong>702,767</strong>, Tulsa at 411,894, Norman with 130,046, Broken Arrow at 119,194, and Edmond with 98,103.\n",
      "URL: https://www.oklahoma-demographics.com/cities_by_population\n",
      "\n",
      "Title: Oklahoma City, OK\n",
      "Description: Oklahoma City, Oklahoma has a population of <strong>688,700</strong>. The median household income is $66,700 and 15% of residents live below the federal poverty level. The racial and ethnic composition is 22% Hispanic, 51% White, 13% Black, 4% Asian and 2% American Indian or Alaska Native.\n",
      "URL: https://bigcitieshealthdata.org/city/oklahoma-city-ok/\n",
      "\n",
      "Title: Oklahoma Cities by Population 2025\n",
      "Description: Oklahoma City is the biggest city in Oklahoma, with a population of <strong>715,893 in 2025</strong>.\n",
      "URL: https://worldpopulationreview.com/us-cities/oklahoma\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "[Multi-Tool Agent] Output: I still don't see a specific figure for exactly 2022, but I can gather enough information to make a reasonable estimate.\n",
      "\n",
      "[Multi-Tool Agent] Tool call: think(thought=From the search results, I can see:\n",
      "1. The 2020 census population was 681,054\n",
      "2. Oklahoma City grew by about 1% between 2022 and 2023, adding 7,589 people\n",
      "3. This implies the 2022 population was approximately 7,589/0.01 = 758,900 people\n",
      "4. But this seems too high compared to other figures like 702,767 and 688,700 mentioned\n",
      "\n",
      "Let me reconsider. If Oklahoma City added 7,589 people between 2022-2023 and that represented a 1% growth, then the 2022 population would be:\n",
      "7,589 ÷ 0.01 = 758,900\n",
      "\n",
      "However, this contradicts other data points. Perhaps the clearest estimate is from the second search result which states: \"The metro area population of Oklahoma City in 2022 was 1,008,000\". But this refers to the metro area (larger than just the city proper).\n",
      "\n",
      "Another data point from the first search states \"Oklahoma City has a 2025 population of 715,893\" and mentions it \"has increased by 4.8% since the most recent census, which recorded a population of 683,078 in 2020.\"\n",
      "\n",
      "If the growth was relatively steady from 2020 to 2025, the annual growth rate would be about 0.96% per year. \n",
      "Using that rate, the 2022 population would be approximately:\n",
      "683,078 × (1.0096)² = 683,078 × 1.0193 = 696,272\n",
      "\n",
      "This seems most consistent with the other data points. I'll use 696,272 as the best estimate for Oklahoma City's 2022 population.)\n",
      "\n",
      "[Multi-Tool Agent] Tool result: Thinking complete!\n",
      "\n",
      "[Multi-Tool Agent] Output: Based on the available data, I can estimate that Oklahoma City's population in 2022 was approximately 696,272 people. Now I'll calculate the square root of this number.\n",
      "\n",
      "[Multi-Tool Agent] Tool call: calculator(number1=696272, number2=0, operator=sqrt)\n",
      "\n",
      "[Multi-Tool Agent] Tool result: Result: 834.4291461831855\n",
      "\n",
      "[Multi-Tool Agent] Output: The square root of Oklahoma City's population in 2022 (estimated at 696,272 people) is approximately 834.43.\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "Message(id='msg_016wLY8JCd5baUgaWEHcrage', content=[TextBlock(text=\"The square root of Oklahoma City's population in 2022 (estimated at 696,272 people) is approximately 834.43.\", type='text')], model='claude-3-7-sonnet-20250219', role='assistant', stop_reason='end_turn', stop_sequence=None, type='message', usage=Usage(input_tokens=5, output_tokens=34, cache_creation_input_tokens=150, cache_read_input_tokens=3881, service_tier='standard'))"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Example query\n",
    "agent.run(\"What's the square root of the OKC population in 2022\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Loaded 3 MCP tools from 2 servers.\n",
      "\n",
      "[Multi-Tool Agent] Received: How many bananas will fit in an Toyota GR86?\n",
      "\n",
      "[Multi-Tool Agent] Output: That's an interesting question! To answer how many bananas will fit in a Toyota GR86, I'll need to find information about the car's cargo capacity and then estimate how many bananas could fit in that space.\n",
      "\n",
      "[Multi-Tool Agent] Tool call: brave_web_search(query=Toyota GR86 cargo capacity trunk volume)\n",
      "\n",
      "[Multi-Tool Agent] Tool result: Title: Cargo space. What can it fit? : r/GR86\n",
      "Description: 11 votes, 36 comments. 42K subscribers in the <strong>GR86</strong> community. For anyone interested in the <strong>Toyota</strong> <strong>GR86</strong> &amp; Subaru BRZ (&#x27;22+).\n",
      "URL: https://www.reddit.com/r/GR86/comments/16xh6ii/cargo_space_what_can_it_fit/\n",
      "\n",
      "Title: 2024 Toyota GR86 Review, Pricing, and Specs\n",
      "Description: The 2024 <strong>Toyota</strong> <strong>GR86</strong> turns every day into an autocross day thanks to its playful chassis and easy-to-slide rear-wheel drive antics.\n",
      "URL: https://www.caranddriver.com/toyota/gr-86/specs\n",
      "\n",
      "Title: 2023 Toyota GR86 Interior, Cargo Space & Seating | U.S. News\n",
      "Description: &quot;You might not think practicality was a consideration with the GR86, but it is surprisingly useful for weekly errands. Its relatively small <strong>6.3 cubic feet</strong> of trunk space is hampered by its short height. But when the seats are folded, Toyota says the GR86 can hold a set of its own replacement ...\n",
      "URL: https://cars.usnews.com/cars-trucks/toyota/gr86/2023/interior\n",
      "\n",
      "Title: 2025 Toyota GR86 Review, Pricing, and Specs\n",
      "Description: DIMENSIONS Wheelbase: 101.4 in Length: 167.9 in Width: 69.9 in Height: 51.6 in Passenger Volume: <strong>78 ft3 Trunk Volume: 6 ft3</strong> Curb Weight: 2838 lb · C/D TEST RESULTS 60 mph: 5.4 sec 100 mph: 13.8 sec 1/4-Mile: 14.0 sec @ 101 mph 130 mph: 27.2 sec Results above omit 1-ft rollout of 0.3 sec.\n",
      "URL: https://www.caranddriver.com/toyota/gr-86\n",
      "\n",
      "Title: Toyota GR86 dimensions, boot space and similars\n",
      "Description: <strong>Toyota</strong> <strong>GR86</strong> dimensions with interior photos, boot space and measurements of length, width and height. Previous cars and similars in size.\n",
      "URL: https://www.automobiledimension.com/model/toyota/gr86\n",
      "\n",
      "Title: Trunk Size | Toyota GR86 Forum - GT86 Forum, Subaru BRZ Forum, Scion ...\n",
      "Description: It still surprises me that I can fit so much in the <strong>trunk</strong>. I am able to fit my entire paintball gear bag, pods, cleats, 2 cases of paint, mask case, small ice chest, and my extra clothes and smaller items. Gotta enjoy the little things with these beautiful cars!\n",
      "URL: https://www.gr86.org/threads/trunk-size.8574/\n",
      "\n",
      "Title: Toyota GR86 Cargo Space | Toyota GR86 Forum - GT86 Forum, Subaru BRZ Forum, Scion ...\n",
      "Description: Not sure if serious or market differences, but it is mandated in all cars in the U.S. if the <strong>trunk</strong> is much bigger than a shoebox lol. ... This is an older thread, you may not receive a response, and could be reviving an old thread. Please consider creating a new thread. ... <strong>Toyota</strong> <strong>GR86</strong> Forum ...\n",
      "URL: https://www.gr86.org/threads/toyota-gr86-cargo-space.372/\n",
      "\n",
      "Title: GR86 - GR86 Boot Dimensions | Toyota GR Forum for owners of GR Yaris, GR86, GR Supra and GR Corolla\n",
      "Description: During my time with the GR86, I tried to take accurate measurements of the boot dimensions (in centimetres), as shown below. Sorry the pictures are not exactly to scale - my MS Paint skills are rather limited! = The boot opening is <strong>60cm at its narrowest (at the bottom), 80cm at the widest</strong>...\n",
      "URL: https://www.gr-zoo.com/threads/gr86-boot-dimensions.2567/\n",
      "\n",
      "Title: 2025 Toyota GR86 Interior, Cargo Space & Seating | U.S. News\n",
      "Description: Few sports cars have large trunks, and the GR86 is no exception. It has just <strong>6.3 cubic feet</strong> of trunk space, which is not much even for this class. You can fit several grocery bags or a couple of carry-on bags with the rear seats upright.\n",
      "URL: https://cars.usnews.com/cars-trucks/toyota/gr86/interior\n",
      "\n",
      "Title: Toyota GR86 (2025) boot space & practicality\n",
      "Description: Read what our experts think about the <strong>Toyota</strong> <strong>GR86</strong>&#x27;s practicality, boot size and overall dimensions, how it compares to its rivals and more.\n",
      "URL: https://www.parkers.co.uk/toyota/gr86/review/practicality/\n",
      "\n",
      "[Multi-Tool Agent] Output: Now I need to get information about the average size of a banana to make this calculation:\n",
      "\n",
      "[Multi-Tool Agent] Tool call: brave_web_search(query=average banana size dimensions volume)\n",
      "\n",
      "[Multi-Tool Agent] Tool result: Title: Banana for scale - Universal converter - Unit conversion for all!\n",
      "Description: Introducing the <strong>banana</strong> as the universal measurement unit, all conversion-related confusion can be avoided. Use this handy app to convert imperial and metric measurements to universal <strong>bananas</strong>.\n",
      "URL: http://bananaforscale.info/\n",
      "\n",
      "Title: How big is a banana? - Quora\n",
      "Description: Answer (1 of 10): How big is a <strong>banana</strong>? Is that your <strong>banana</strong> or my <strong>banana</strong>? Musa Ingens, the world&#x27;s largest <strong>banana</strong> tree growing in the forest of Papua New Guinea and Indonesia. It is the tallest species of <strong>bananas</strong> and the world&#x27;s largest herbaceous plant. The <strong>size</strong> of the Musa Ingens <strong>banana</strong> is imp...\n",
      "URL: https://www.quora.com/How-big-is-a-banana\n",
      "\n",
      "Title: How Many Calories and Carbs Are in a Banana?\n",
      "Description: <strong>Bananas</strong> are extremely healthy and nutritious. Most people know this, but many wonder how many calories and carbs <strong>bananas</strong> contain.\n",
      "URL: https://www.healthline.com/nutrition/bananas-calories-carbs\n",
      "\n",
      "Title: Banana - Wikipedia\n",
      "Description: As of 2018, <strong>bananas</strong> are exported in larger <strong>volume</strong> and to a larger value than any other fruit. In 2022, world production of <strong>bananas</strong> and plantains combined was 179 million tonnes, led by India and China with a combined total of 26% of global production. Other major producers were Uganda, Indonesia, ...\n",
      "URL: https://en.wikipedia.org/wiki/Banana\n",
      "\n",
      "Title: On the Usefulness of Bananas: A New System of Measurement | by Liam Foley | Medium\n",
      "Description: According to a study conducted by Mahmoud Soltani of the University of Tehran, on average, a fully ripe banana fruit of the Cavendish variety measures 200.25 millimetres in length, with a mass of 180.56 grams, and an ellipsoid volume of <strong>156.10 cubic centimetres</strong>.\n",
      "URL: https://medium.com/@liamfoley2430/on-the-usefulness-of-bananas-a-new-system-of-measurement-76c50d8bb89a\n",
      "\n",
      "Title: Banana-based Length & Distance Unit Converter | Convert To Bananas\n",
      "Description: Convert any length to <strong>bananas</strong> (and to useful units as well)\n",
      "URL: https://www.converttobananas.com/\n",
      "\n",
      "Title: r/atlanticdiscussions on Reddit: HOW LONG IS THE, UM, AVERAGE BANANA? And why do you all want to know so bad?\n",
      "Description: As a writer on the internet, I often feel as though I’m getting a peek into the American mind. Recently, while looking at search data, I discovered…\n",
      "URL: https://www.reddit.com/r/atlanticdiscussions/comments/pbenqf/how_long_is_the_um_average_banana_and_why_do_you/\n",
      "\n",
      "Title: How Long Is the, Um, Average Banana?\n",
      "Description: <strong>Bananas</strong> come in a total of five <strong>sizes</strong> — extra small, small, medium, large and extra large. But how long is the <strong>average</strong> <strong>banana</strong>?\n",
      "URL: https://melmagazine.com/en-us/story/how-long-is-a-banana\n",
      "\n",
      "Title: r/theydidthemath on Reddit: [Request] Assuming the bananas are normal size how many rooms would 102,769 bananas fill?\n",
      "Description: The average volume of a banana is <strong>156.1 cm³</strong>. Assuming you mean whole, uncrushed bananas, google search results peg the packing effeciency around 65%.\n",
      "URL: https://www.reddit.com/r/theydidthemath/comments/rdiyis/request_assuming_the_bananas_are_normal_size_how/\n",
      "\n",
      "Title: How big is your banana?\n",
      "Description: BMI Calculator Enter your details: Height (cm): Weight (kg): BMI (kg/m2) is Category is\n",
      "URL: https://healthieryou.net.au/wp-content/uploads/2015/11/How-big-is-your-banana-Article.pdf\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "[Multi-Tool Agent] Output: Now I have the information I need to calculate how many bananas will fit in a Toyota GR86. Let me think through this:\n",
      "\n",
      "[Multi-Tool Agent] Tool call: think(thought=From the search results, I found:\n",
      "\n",
      "1. Toyota GR86 trunk capacity:\n",
      "   - 6.3 cubic feet of trunk space (according to multiple sources)\n",
      "   - This equals approximately 178,385 cubic centimeters (6.3 ft³ × 28,316.85 cm³/ft³)\n",
      "\n",
      "2. Average banana volume:\n",
      "   - A fully ripe Cavendish banana has a volume of approximately 156.10 cubic centimeters\n",
      "\n",
      "3. Packing efficiency:\n",
      "   - When packing irregular objects like bananas, we need to account for the space between them\n",
      "   - A Reddit comment mentioned packing efficiency of around 65% for bananas\n",
      "   - This means only about 65% of the total volume can be filled with bananas due to gaps\n",
      "\n",
      "So to calculate how many bananas will fit in the Toyota GR86 trunk:\n",
      "- Available volume with packing efficiency: 178,385 cm³ × 0.65 = 115,950 cm³\n",
      "- Number of bananas: 115,950 cm³ ÷ 156.10 cm³ = 743 bananas\n",
      "\n",
      "However, the Toyota GR86 also has an interior cabin with a passenger volume of approximately 78 ft³ (according to one of the search results). If we were to fill the entire car with bananas (which is not practical but answers the hypothetical question):\n",
      "\n",
      "Total car volume = 78 ft³ (passenger) + 6.3 ft³ (trunk) = 84.3 ft³ = 2,387,110 cm³\n",
      "\n",
      "With 65% packing efficiency:\n",
      "- Available volume: 2,387,110 cm³ × 0.65 = 1,551,622 cm³\n",
      "- Number of bananas: 1,551,622 cm³ ÷ 156.10 cm³ = 9,940 bananas\n",
      "\n",
      "So, approximately 9,940 bananas could theoretically fit in an entire Toyota GR86 if completely filled, or about 743 bananas in just the trunk.)\n",
      "\n",
      "[Multi-Tool Agent] Tool result: Thinking complete!\n",
      "\n",
      "[Multi-Tool Agent] Output: # How Many Bananas Will Fit in a Toyota GR86\n",
      "\n",
      "Based on my research, I can provide you with an estimate of how many bananas would fit in a Toyota GR86.\n",
      "\n",
      "## The Data:\n",
      "\n",
      "- **Toyota GR86 trunk capacity**: 6.3 cubic feet (approximately 178,385 cubic centimeters)\n",
      "- **Toyota GR86 passenger volume**: 78 cubic feet\n",
      "- **Average banana volume**: 156.10 cubic centimeters per banana\n",
      "- **Packing efficiency**: Approximately 65% (accounting for inevitable gaps between irregularly shaped bananas)\n",
      "\n",
      "## The Calculation:\n",
      "\n",
      "If we're talking about filling just the trunk:\n",
      "- Available volume with packing efficiency: 178,385 cm³ × 0.65 = 115,950 cm³\n",
      "- Number of bananas in trunk: 115,950 cm³ ÷ 156.10 cm³ = approximately **743 bananas**\n",
      "\n",
      "If we're considering the entire car (including passenger compartment):\n",
      "- Total car volume: 84.3 cubic feet (2,387,110 cm³)\n",
      "- Available volume with packing efficiency: 2,387,110 cm³ × 0.65 = 1,551,622 cm³\n",
      "- Total number of bananas: 1,551,622 cm³ ÷ 156.10 cm³ = approximately **9,940 bananas**\n",
      "\n",
      "So, you could fit approximately 743 bananas in the trunk alone, or nearly 10,000 bananas if you filled the entire Toyota GR86 (though that would leave no room for a driver!).\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "Message(id='msg_01NC46TLNZSG97ZH5v7b7YcN', content=[TextBlock(text=\"# How Many Bananas Will Fit in a Toyota GR86\\n\\nBased on my research, I can provide you with an estimate of how many bananas would fit in a Toyota GR86.\\n\\n## The Data:\\n\\n- **Toyota GR86 trunk capacity**: 6.3 cubic feet (approximately 178,385 cubic centimeters)\\n- **Toyota GR86 passenger volume**: 78 cubic feet\\n- **Average banana volume**: 156.10 cubic centimeters per banana\\n- **Packing efficiency**: Approximately 65% (accounting for inevitable gaps between irregularly shaped bananas)\\n\\n## The Calculation:\\n\\nIf we're talking about filling just the trunk:\\n- Available volume with packing efficiency: 178,385 cm³ × 0.65 = 115,950 cm³\\n- Number of bananas in trunk: 115,950 cm³ ÷ 156.10 cm³ = approximately **743 bananas**\\n\\nIf we're considering the entire car (including passenger compartment):\\n- Total car volume: 84.3 cubic feet (2,387,110 cm³)\\n- Available volume with packing efficiency: 2,387,110 cm³ × 0.65 = 1,551,622 cm³\\n- Total number of bananas: 1,551,622 cm³ ÷ 156.10 cm³ = approximately **9,940 bananas**\\n\\nSo, you could fit approximately 743 bananas in the trunk alone, or nearly 10,000 bananas if you filled the entire Toyota GR86 (though that would leave no room for a driver!).\", type='text')], model='claude-3-7-sonnet-20250219', role='assistant', stop_reason='end_turn', stop_sequence=None, type='message', usage=Usage(input_tokens=4, output_tokens=385, cache_creation_input_tokens=574, cache_read_input_tokens=6630, service_tier='standard'))"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "await agent.run_async(\"How many bananas will fit in an Toyota GR86?\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 4. Example with Anthropic Server Tools\n",
    "\n",
    "This example demonstrates using Anthropic's native server tools for web search and code execution."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "[Server Tools Agent] Agent initialized\n"
     ]
    }
   ],
   "source": [
    "# Create Anthropic server tools\n",
    "web_search_tool = WebSearchServerTool(\n",
    "    name=\"web_search\",\n",
    "    max_uses=5,  # Limit to 5 searches per request\n",
    "    blocked_domains=[\"example.com\"]  # Example of blocking specific domains\n",
    ")\n",
    "\n",
    "code_execution_tool = CodeExecutionServerTool()\n",
    "\n",
    "# Initialize agent with server tools\n",
    "server_agent = Agent(\n",
    "    name=\"Server Tools Agent\",\n",
    "    system=\"\"\"\n",
    "You are a helpful assistant with access to:\n",
    "1. Web search for finding current information\n",
    "2. Code execution for running Python code\n",
    "3. Think tool for complex reasoning\n",
    "\n",
    "Use these tools effectively to answer questions that require current data or calculations.\n",
    "\"\"\",\n",
    "    tools=[think_tool, web_search_tool, code_execution_tool],\n",
    "    config=ModelConfig(\n",
    "        model=\"claude-sonnet-4-20250514\",\n",
    "        max_tokens=4096,\n",
    "        temperature=0.7\n",
    "    ),\n",
    "    verbose=True\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "[Server Tools Agent] Received: \n",
      "Search for the current population of Tokyo, Japan. \n",
      "Then write and execute Python code to calculate how many people that would be per square kilometer, \n",
      "given that Tokyo's area is approximately 2,194 square kilometers.\n",
      "\n",
      "\n",
      "[Server Tools Agent] Output: I'll help you find Tokyo's current population and then calculate the population density. Let me start by searching for the current population data.\n",
      "\n",
      "[Server Tools Agent] Output: Now let me search for more specific information about Tokyo's current population, as the results show different figures for different definitions of \"Tokyo\" (city proper vs metropolitan area).\n",
      "\n",
      "[Server Tools Agent] Tool call: think(thought=Now I have a clearer picture of Tokyo's population. From the search results, I can see there are different definitions of \"Tokyo\":\n",
      "\n",
      "1. Tokyo Metropolis (Tokyo-to) - the prefecture/administrative area: Around 14 million people as of 2024\n",
      "2. The 23 Special Wards (central Tokyo): Around 9.2-9.7 million people\n",
      "3. Greater Tokyo Area (metropolitan area): Around 37 million people\n",
      "\n",
      "For the calculation with the given area of 2,194 square kilometers, this seems to refer to the Tokyo Metropolis (Tokyo-to) area, as the search results mention:\n",
      "- \"metropolis population is 13.9 Million as on 2019 and has area of 2,194 Sq km\" (from source 17)\n",
      "- The surface area of the city metropolis comes to approximately 2,187.66 km² (from source 2)\n",
      "\n",
      "So I should use approximately 14 million as the current population for Tokyo Metropolis for the calculation with the 2,194 sq km area.\n",
      "\n",
      "Let me write Python code to calculate the population density.)\n",
      "\n",
      "[Server Tools Agent] Tool result: Thinking complete!\n",
      "\n",
      "[Server Tools Agent] Output: Now I'll write and execute Python code to calculate Tokyo's population density based on the information I found.\n",
      "\n",
      "[Server Tools Agent] Output: Based on my search and calculations, here are the key findings:\n",
      "\n",
      "## Tokyo's Current Population\n",
      "\n",
      "\n",
      "\n",
      "[Server Tools Agent] Output: Tokyo Metropolis (Tokyo-to) has a population of over 14 million people as of 2023-2024\n",
      "\n",
      "[Server Tools Agent] Output: . The search results show different figures depending on the specific definition of \"Tokyo\":\n",
      "\n",
      "- \n",
      "\n",
      "[Server Tools Agent] Output: The 23 wards have a population of 9.2 million\n",
      "\n",
      "[Server Tools Agent] Output: \n",
      "- \n",
      "\n",
      "[Server Tools Agent] Output: The metropolis has a population that exceeds 13 million\n",
      "\n",
      "[Server Tools Agent] Output: \n",
      "- \n",
      "\n",
      "[Server Tools Agent] Output: The Greater Tokyo Area has 41 million residents as of 2024\n",
      "\n",
      "[Server Tools Agent] Output: \n",
      "\n",
      "## Population Density Calculation\n",
      "\n",
      "Using the current population of approximately **14 million people** for Tokyo Metropolis and the given area of **2,194 square kilometers**, the calculation shows:\n",
      "\n",
      "**Tokyo's population density is approximately 6,381 people per square kilometer**\n",
      "\n",
      "This aligns well with existing data, as \n",
      "\n",
      "[Server Tools Agent] Output: one source indicates Tokyo metropolis has a density of 6,349 persons per square kilometer\n",
      "\n",
      "[Server Tools Agent] Output: , confirming our calculation is accurate.\n",
      "\n",
      "## Context\n",
      "\n",
      "This makes Tokyo one of the most densely populated metropolitan areas in the world. \n",
      "\n",
      "[Server Tools Agent] Output: The greater Tokyo metropolitan area is estimated to be over 36 million people and is home to 25% of Japan's population, making it the most populous metropolitan area in the world\n",
      "\n",
      "[Server Tools Agent] Output: .\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "Message(id='msg_018nAgEXuVMSJCTSrSjcZtrj', content=[TextBlock(text=\"Now I'll write and execute Python code to calculate Tokyo's population density based on the information I found.\", type='text'), TextBlock(text=None, type='server_tool_use', id='srvtoolu_01JAxi9fcajoScWQWEG1bJ2S', name='code_execution', input={'code': '# Tokyo population and area data\\n# Based on search results, Tokyo Metropolis (Tokyo-to) has approximately 14 million people\\n# and covers 2,194 square kilometers\\n\\ntokyo_population = 14_000_000  # Current population of Tokyo Metropolis (2024)\\ntokyo_area_sq_km = 2194  # Area in square kilometers\\n\\n# Calculate population density\\npopulation_density = tokyo_population / tokyo_area_sq_km\\n\\nprint(\"Tokyo Population Density Calculation\")\\nprint(\"=\" * 40)\\nprint(f\"Tokyo Metropolis Population: {tokyo_population:,} people\")\\nprint(f\"Tokyo Metropolis Area: {tokyo_area_sq_km:,} square kilometers\")\\nprint(f\"Population Density: {population_density:,.2f} people per square kilometer\")\\n\\n# Let\\'s also show some context with rounded numbers\\nprint(f\"\\\\nRounded: Approximately {population_density:,.0f} people per square kilometer\")\\n\\n# For comparison, let\\'s also calculate for different population estimates\\nprint(\"\\\\n\" + \"=\"*50)\\nprint(\"COMPARISON WITH DIFFERENT POPULATION ESTIMATES:\")\\nprint(\"=\"*50)\\n\\n# Different population estimates from search results\\nestimates = [\\n    (\"Tokyo Metropolis (conservative estimate)\", 13_500_000),\\n    (\"Tokyo Metropolis (current estimate)\", 14_000_000),\\n    (\"Tokyo Metropolis (high estimate)\", 14_300_000),\\n]\\n\\nfor description, population in estimates:\\n    density = population / tokyo_area_sq_km\\n    print(f\"{description}: {density:,.0f} people/km²\")'}), TextBlock(text=None, type='code_execution_tool_result', tool_use_id='srvtoolu_01JAxi9fcajoScWQWEG1bJ2S', content={'type': 'code_execution_result', 'stdout': 'Tokyo Population Density Calculation\\n========================================\\nTokyo Metropolis Population: 14,000,000 people\\nTokyo Metropolis Area: 2,194 square kilometers\\nPopulation Density: 6,381.04 people per square kilometer\\n\\nRounded: Approximately 6,381 people per square kilometer\\n\\n==================================================\\nCOMPARISON WITH DIFFERENT POPULATION ESTIMATES:\\n==================================================\\nTokyo Metropolis (conservative estimate): 6,153 people/km²\\nTokyo Metropolis (current estimate): 6,381 people/km²\\nTokyo Metropolis (high estimate): 6,518 people/km²\\n', 'stderr': '', 'return_code': 0, 'content': []}), TextBlock(text=\"Based on my search and calculations, here are the key findings:\\n\\n## Tokyo's Current Population\\n\\n\", type='text'), TextBlock(text='Tokyo Metropolis (Tokyo-to) has a population of over 14 million people as of 2023-2024', type='text', citations=[{'type': 'web_search_result_location', 'cited_text': 'With a population of over 14 million in the city proper in 2023, it is one of the most populous urban areas in the world. ', 'url': 'https://en.wikipedia.org/wiki/Tokyo', 'title': 'Tokyo - Wikipedia', 'encrypted_index': 'Eo8BCioIBBgCIiQ3NmU4ZmI4OC1kOGFhLTQwMzMtYjQ1Mi1lMmZlY2M3MGFiZjkSDNkmb67meDKwvfNSWBoMey/C2mf4C76VGRm/IjB/p9OlOe00CdTjisZ+Soyr8DL2IDH8J+LioeVOOHK7L/3HfUnClNRaZvtHREGHnFQqE0Pko8rhETBI/USi53r6+Vq2i1sYBA=='}, {'type': 'web_search_result_location', 'cited_text': 'The area within the dashed white line is home to 14 million people, as of 2020. ', 'url': 'http://www.statsmapsnpix.com/2022/09/how-big-is-tokyo.html', 'title': 'Stats, Maps n Pix: How big is Tokyo?', 'encrypted_index': 'EpABCioIBBgCIiQ3NmU4ZmI4OC1kOGFhLTQwMzMtYjQ1Mi1lMmZlY2M3MGFiZjkSDN3Dl6f/w5+R2DpZzRoMZiaU1oKXtaWciBkzIjCeqzTw6VNVH9T8pJcQGylS/KdoN8tamtX70LsJ7ygZeDUBnbVxfCebu8Xfpv9tdJAqFN2KZA2z6Q/22MX5gewO0+OfwUtrGAQ='}, {'type': 'web_search_result_location', 'cited_text': 'The area within the dashed white line is home to 14 million people, as of 2020. ', 'url': 'http://www.statsmapsnpix.com/2022/09/how-big-is-tokyo.html', 'title': 'Stats, Maps n Pix: How big is Tokyo?', 'encrypted_index': 'EpABCioIBBgCIiQ3NmU4ZmI4OC1kOGFhLTQwMzMtYjQ1Mi1lMmZlY2M3MGFiZjkSDPgOVKuta9qNyug8dRoMzPFdKW3fR2mvZIK7IjCUZybt1VVAMoVOA3VEOCprNID+ZQWavx0Z9ug53tjoeanpJvyGUIqn65McFNAKksEqFDn6oY/apm+AjLJk908w1NyD4w0OGAQ='}]), TextBlock(text='. The search results show different figures depending on the specific definition of \"Tokyo\":\\n\\n- ', type='text'), TextBlock(text='The 23 wards have a population of 9.2 million', type='text', citations=[{'type': 'web_search_result_location', 'cited_text': 'The 23 wards claim a population of 9.2 million, but the metropolis has a population that exceeds 13 million. ', 'url': 'https://worldpopulationreview.com/cities/japan/tokyo', 'title': 'Tokyo Population 2025', 'encrypted_index': 'Eo8BCioIBBgCIiQ3NmU4ZmI4OC1kOGFhLTQwMzMtYjQ1Mi1lMmZlY2M3MGFiZjkSDGHmgL6AaaF2lV1RIBoMst2h5K/VIu2RGDTwIjBLqvkNQPtkPP1V49Wf9IxwZBOyM+HgBvi7rd6yR/Wkjr9LpT3HnIQOT5FetsLzqUoqE5k8jG1Xsz7hyicRcL/9UCJHKU8YBA=='}]), TextBlock(text='\\n- ', type='text'), TextBlock(text='The metropolis has a population that exceeds 13 million', type='text', citations=[{'type': 'web_search_result_location', 'cited_text': 'The 23 wards claim a population of 9.2 million, but the metropolis has a population that exceeds 13 million. ', 'url': 'https://worldpopulationreview.com/cities/japan/tokyo', 'title': 'Tokyo Population 2025', 'encrypted_index': 'Eo8BCioIBBgCIiQ3NmU4ZmI4OC1kOGFhLTQwMzMtYjQ1Mi1lMmZlY2M3MGFiZjkSDHsQQzoI+Hz+TiOD7xoMgVi2a9XbrLmJlkNKIjCXGiOzb7fzGY/ueYkCuE280j3RfDhLCJ3YWi6gVboWe2BidSHKRwJBoPbhHAaWwVYqEwZ9kwdNZiabocE1Kbh3m6GW/SMYBA=='}, {'type': 'web_search_result_location', 'cited_text': 'The 23 wards claim a population of 9.2 million, but the metropolis has a population that exceeds 13 million. ', 'url': 'https://worldpopulationreview.com/cities/japan/tokyo', 'title': 'Tokyo Population 2025', 'encrypted_index': 'EpEBCioIBBgCIiQ3NmU4ZmI4OC1kOGFhLTQwMzMtYjQ1Mi1lMmZlY2M3MGFiZjkSDHolkkUxMX/ORAlhZBoMoDhnLJx+SR+8R8aTIjDBKIO2DJG07HcLucjTH1y1LCGBRw1mv/t061+rSVpTbV7iY5DXREoEUGCcMFVasUgqFT9KXif7+m2jD/0yN42wWd02HG+jbRgE'}]), TextBlock(text='\\n- ', type='text'), TextBlock(text='The Greater Tokyo Area has 41 million residents as of 2024', type='text', citations=[{'type': 'web_search_result_location', 'cited_text': 'The Greater Tokyo Area, which includes Tokyo and parts of six neighboring prefectures, is the most populous metropolitan area in the world, with 41 mi...', 'url': 'https://en.wikipedia.org/wiki/Tokyo', 'title': 'Tokyo - Wikipedia', 'encrypted_index': 'Eo8BCioIBBgCIiQ3NmU4ZmI4OC1kOGFhLTQwMzMtYjQ1Mi1lMmZlY2M3MGFiZjkSDPu/83J4h+//6WejfhoMabArnZYopPgIgBadIjABzh8N5tuANZ8z7yijY+HpuAP+iw6WDSwqolJU6364du78SvzlqUXbWLujKQdIhMcqE1fHzX0qTHJmNVRZHIt3AcmEBLwYBA=='}]), TextBlock(text=\"\\n\\n## Population Density Calculation\\n\\nUsing the current population of approximately **14 million people** for Tokyo Metropolis and the given area of **2,194 square kilometers**, the calculation shows:\\n\\n**Tokyo's population density is approximately 6,381 people per square kilometer**\\n\\nThis aligns well with existing data, as \", type='text'), TextBlock(text='one source indicates Tokyo metropolis has a density of 6,349 persons per square kilometer', type='text', citations=[{'type': 'web_search_result_location', 'cited_text': 'Tokyo population in 2023 is estimated to be 35.8 million, population in 2022 is estimated to be 35.6 million, in 2021 is estimated to be 37.5 million,...', 'url': 'https://www.populationu.com/cities/tokyo-population', 'title': 'Tokyo Population 2025', 'encrypted_index': 'EpEBCioIBBgCIiQ3NmU4ZmI4OC1kOGFhLTQwMzMtYjQ1Mi1lMmZlY2M3MGFiZjkSDH+CHv/68jATiDYFzRoMKun6Si5c+OHOiG9WIjAq6lZhNchC2RxsNLZMgheItJe0yOT53PlDChrsyxJztTkx8aSELTlrH+2V953cZhYqFUMI2gojH59prn81fC8mSgHNmvaKKBgE'}]), TextBlock(text=', confirming our calculation is accurate.\\n\\n## Context\\n\\nThis makes Tokyo one of the most densely populated metropolitan areas in the world. ', type='text'), TextBlock(text=\"The greater Tokyo metropolitan area is estimated to be over 36 million people and is home to 25% of Japan's population, making it the most populous metropolitan area in the world\", type='text', citations=[{'type': 'web_search_result_location', 'cited_text': 'The greater Tokyo metropolitan area, which is spread over 3 prefectures, is much larger and has a population that is estimated to be over 36 million. ...', 'url': 'https://worldpopulationreview.com/cities/japan/tokyo', 'title': 'Tokyo Population 2025', 'encrypted_index': 'EpEBCioIBBgCIiQ3NmU4ZmI4OC1kOGFhLTQwMzMtYjQ1Mi1lMmZlY2M3MGFiZjkSDC3eHB8MpV+6PvSJ9hoMGBBbLOOC80uQmSO4IjCujon0QmWYTtDWe+Po+0YK+bXYbwcEwKmurDHUK1IuU6w2rvi9Rq2XeSecqpnOhNgqFU8JodAjBnotfaYFd1dee+V5IBAlIxgE'}]), TextBlock(text='.', type='text')], model='claude-sonnet-4-20250514', role='assistant', stop_reason='end_turn', stop_sequence=None, type='message', usage=Usage(input_tokens=9, output_tokens=841, cache_creation_input_tokens=928, cache_read_input_tokens=48328, service_tier='standard', server_tool_use={'web_search_requests': 0}), container={'id': 'container_011CQTnr9bhVu3fPTnaT85oA', 'expires_at': '2025-06-24T22:55:24.157374+00:00'})"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Example 1: Use web search to find current information and code execution for analysis\n",
    "server_agent.run(\"\"\"\n",
    "Search for the current population of Tokyo, Japan. \n",
    "Then write and execute Python code to calculate how many people that would be per square kilometer, \n",
    "given that Tokyo's area is approximately 2,194 square kilometers.\n",
    "\"\"\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
